package com.sihan.swvp.service.worksy;

import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sihan.swvp.dao.worksy.TaskxsDao;
import com.sihan.swvp.entity.worksy.Taskxs;

@Service
public class TaskxsService {

	@Autowired
	private TaskxsDao taskxsDao;
	
	public Page<Map<String, Object>> getList(Integer page,Integer limit,Map<String, Object> kv){
		PageHelper.startPage(page, limit);
		Page<Map<String, Object>> list = taskxsDao.getList(kv);
		return list;
	}
	
	public void addTaskxs(Taskxs taskxs){
		if(taskxs.getId() != null && !"".equals(taskxs.getId())){
			taskxsDao.updateTaskxs(taskxs);
		}else{
			taskxs.setId(UUID.randomUUID().toString());
			taskxsDao.addTaskxs(taskxs);
		}
	}
	
	public void delById(String id){
		taskxsDao.delById(id);
	}
	
	/*public void addimpExcel(List<Taskxs> list){
		for (Taskxs t : list) {
			//判断系统中是否已有相同编号的数据
			if(taskxsDao.getCountById(t.getId()) > 0){
				taskxsDao.updateTaskxs(t);
				continue;
				//throw new RuntimeException("系统中已经存在编号为 '"+t.getId()+"' 的数据。在Excel第"+t.getExcelRow()+"行");
			}
			//获取班组ID
			Integer bzid = worksyDao.getBzIdByBzcode(t.getBzCode());
			if(bzid == null){
				throw new RuntimeException("数据导入文件中的班组编码 '"+t.getBzCode()+"' 在系统中不存在。在Excel第"+t.getExcelRow()+"行");
			}
			t.setBz_id(bzid);
			//获取专业ID
			Integer zyid = worksyDao.getZyIdByzyCode(t.getZyCode());
			if(zyid == null){
				throw new RuntimeException("数据导入文件中的专业编码 '"+t.getZyCode()+"' 在系统中不存在。在Excel第"+t.getExcelRow()+"行");
			}
			t.setMajor_id(zyid);
		}
		taskxsDao.addTaskxslist(list);
	}*/
	
}
